/*   1:    */ package com.atomikos.icatch.imp;
/*   2:    */ 
/*   3:    */ import com.atomikos.icatch.HeurCommitException;
/*   4:    */ import com.atomikos.icatch.HeurHazardException;
/*   5:    */ import com.atomikos.icatch.HeurMixedException;
/*   6:    */ import com.atomikos.icatch.HeurRollbackException;
/*   7:    */ import com.atomikos.icatch.HeuristicMessage;
/*   8:    */ import com.atomikos.icatch.Participant;
/*   9:    */ import com.atomikos.icatch.RollbackException;
/*  10:    */ import com.atomikos.icatch.SysException;
/*  11:    */ import com.atomikos.icatch.TxState;
/*  12:    */ import com.atomikos.icatch.imp.thread.InterruptedExceptionHelper;
/*  13:    */ import java.util.Enumeration;
/*  14:    */ import java.util.Hashtable;
/*  15:    */ import java.util.Stack;
/*  16:    */ import java.util.Vector;
/*  17:    */ 
/*  18:    */ class HeurHazardStateHandler
/*  19:    */   extends CoordinatorStateHandler
/*  20:    */ {
/*  21:    */   private Vector hazards_;
/*  22:    */   
/*  23:    */   HeurHazardStateHandler(CoordinatorImp coordinator)
/*  24:    */   {
/*  25: 56 */     super(coordinator);
/*  26: 57 */     this.hazards_ = new Vector();
/*  27:    */   }
/*  28:    */   
/*  29:    */   HeurHazardStateHandler(CoordinatorStateHandler previous, Vector hazards)
/*  30:    */   {
/*  31: 63 */     super(previous);
/*  32: 64 */     this.hazards_ = ((Vector)hazards.clone());
/*  33:    */   }
/*  34:    */   
/*  35:    */   HeurHazardStateHandler(CoordinatorStateHandler previous, Hashtable hazards)
/*  36:    */   {
/*  37: 71 */     super(previous);
/*  38: 72 */     this.hazards_ = new Vector();
/*  39: 73 */     this.hazards_.addAll(hazards.keySet());
/*  40:    */   }
/*  41:    */   
/*  42:    */   protected void recover(CoordinatorImp coordinator)
/*  43:    */   {
/*  44: 80 */     super.recover(coordinator);
/*  45:    */     
/*  46:    */ 
/*  47:    */ 
/*  48:    */ 
/*  49: 85 */     Enumeration enumm = getCoordinator().getParticipants().elements();
/*  50: 86 */     while (enumm.hasMoreElements())
/*  51:    */     {
/*  52: 87 */       Participant p = (Participant)enumm.nextElement();
/*  53: 88 */       if (!getReadOnlyTable().containsKey(p)) {
/*  54: 89 */         replayCompletion(p);
/*  55:    */       }
/*  56:    */     }
/*  57:    */   }
/*  58:    */   
/*  59:    */   protected Object getState()
/*  60:    */   {
/*  61: 96 */     return TxState.HEUR_HAZARD;
/*  62:    */   }
/*  63:    */   
/*  64:    */   protected void onTimeout()
/*  65:    */   {
/*  66:103 */     boolean committed = getCommitted().booleanValue();
/*  67:    */     
/*  68:105 */     addAllForReplay(this.hazards_);
/*  69:    */     
/*  70:    */ 
/*  71:    */ 
/*  72:109 */     Stack replayStack = getReplayStack();
/*  73:110 */     boolean replay = false;
/*  74:111 */     if (!replayStack.empty())
/*  75:    */     {
/*  76:112 */       replay = true;
/*  77:113 */       int count = replayStack.size();
/*  78:114 */       TerminationResult result = new TerminationResult(count);
/*  79:116 */       while (!replayStack.empty())
/*  80:    */       {
/*  81:117 */         Participant part = (Participant)replayStack.pop();
/*  82:118 */         if (committed)
/*  83:    */         {
/*  84:119 */           CommitMessage cm = new CommitMessage(part, result, false);
/*  85:120 */           getPropagator().submitPropagationMessage(cm);
/*  86:    */         }
/*  87:    */         else
/*  88:    */         {
/*  89:122 */           RollbackMessage rm = new RollbackMessage(part, result, true);
/*  90:    */           
/*  91:124 */           getPropagator().submitPropagationMessage(rm);
/*  92:    */         }
/*  93:    */       }
/*  94:    */       try
/*  95:    */       {
/*  96:128 */         result.waitForReplies();
/*  97:    */         
/*  98:    */ 
/*  99:    */ 
/* 100:    */ 
/* 101:133 */         Stack replies = result.getReplies();
/* 102:    */         
/* 103:135 */         Enumeration enumm = replies.elements();
/* 104:136 */         while (enumm.hasMoreElements())
/* 105:    */         {
/* 106:137 */           Reply reply = (Reply)enumm.nextElement();
/* 107:139 */           if (!reply.hasFailed()) {
/* 108:140 */             this.hazards_.remove(reply.getParticipant());
/* 109:    */           }
/* 110:    */         }
/* 111:    */       }
/* 112:    */       catch (InterruptedException inter)
/* 113:    */       {
/* 114:152 */         InterruptedExceptionHelper.handleInterruptedException(inter);
/* 115:    */       }
/* 116:    */     }
/* 117:159 */     if (this.hazards_.isEmpty())
/* 118:    */     {
/* 119:160 */       TerminatedStateHandler termStateHandler = new TerminatedStateHandler(this);
/* 120:    */       
/* 121:162 */       getCoordinator().setStateHandler(termStateHandler);
/* 122:    */     }
/* 123:163 */     else if (replay)
/* 124:    */     {
/* 125:167 */       getCoordinator().setStateHandler(this);
/* 126:    */     }
/* 127:    */   }
/* 128:    */   
/* 129:    */   protected void setGlobalSiblingCount(int count) {}
/* 130:    */   
/* 131:    */   protected int prepare()
/* 132:    */     throws RollbackException, IllegalStateException, HeurHazardException, HeurMixedException, SysException
/* 133:    */   {
/* 134:181 */     throw new HeurHazardException(getHeuristicMessages());
/* 135:    */   }
/* 136:    */   
/* 137:    */   protected HeuristicMessage[] commit(boolean onePhase)
/* 138:    */     throws HeurRollbackException, HeurMixedException, HeurHazardException, IllegalStateException, RollbackException, SysException
/* 139:    */   {
/* 140:190 */     throw new HeurHazardException(getHeuristicMessages());
/* 141:    */   }
/* 142:    */   
/* 143:    */   protected HeuristicMessage[] rollback()
/* 144:    */     throws HeurCommitException, HeurMixedException, SysException, HeurHazardException, IllegalStateException
/* 145:    */   {
/* 146:198 */     throw new HeurHazardException(getHeuristicMessages());
/* 147:    */   }
/* 148:    */ }


/* Location:           C:\myfile\mysoft\apache-maven-3.5.0-bin\apache-maven-3.5.0\myrep\com\atomikos\transactions\3.7.0\transactions-3.7.0.jar
 * Qualified Name:     com.atomikos.icatch.imp.HeurHazardStateHandler
 * JD-Core Version:    0.7.0.1
 */